<cfif isDefined("form.cmd")>

   <cfset VAL1b = "">
   <cfif isDefined("form.val1")>
     <cfset VAL1a = Form.val1>
     <cfset VAL1a = "#ReReplace(VAL1,"\\",sep,"ALL")#">
     <cfset VAL1a = "#ReReplace(VAL1,"//",sep,"ALL")#">
     <cfset VAL1a = "#ReReplace(VAL1a,"/",sep,"ALL")#">
     <cfif Compare(Mid(VAL1a,1,3),sep & "..") is "0">
	    <cfabort>
	 </cfif>
     <cfset VAL1b = "#upload_dir#" & "#TRIM(VAL1a)#">
   </cfif>

   <cfset VAL2 = "">
   <cfif isDefined("form.val2")>
     <cfset VAL2 = Form.val2>
     <cfset VAL2 = ReReplace(VAL2,"\\",sep,"ALL")>
     <cfset VAL2 = ReReplace(VAL2,"//",sep,"ALL")>
     <cfset VAL2 = ReReplace(VAL2,"/",sep,"ALL")>
     <cfif Compare(Mid(VAL2,1,3),sep & "..") is "0">
	    <cfabort>
	 </cfif>
     <cfset VAL2 = "#upload_dir#" & "#VAL2#">
   </cfif>

   <cfset error = 0>

<!--- List the Directory --->
<cfif Form.CMD is "list">
<cfset folder = "#VAL1b#">
<cfdirectory action="list" directory="#VAL1b#" name="ListDir">
<!--- loop over the query and send it to the applet --->
<pre>
<!--- cffile does not return "." and ".."
WARNING WARNING WARNING
You can put it in manualy but if RECURSIVE is set on cffile delete, and someone does a delete on "."
or worse .. it will remove the entire contents of the directory and the parent directory --->
<!--- DO NOT USE
Dir 0 0 ..<br> --->
<cfoutput query="listdir">
<cfset FileDateTime = CreateODBCDateTime(DATELASTMODIFIED)>
#type# #FileDateTime.getTime()# #size# #name#<br>
</cfoutput>
</pre>

   <!--- Make a directory --->
   <cfelseif Form.CMD is "mkdir">
  	  <cfdirectory action="Create" directory="#VAL1b#">
	  <!--- the status/error condition is sent via the headers --->

   <!--- Delete Directory or File? --->
   <cfelseif Form.CMD is "del">
	  <cftry>
		  <cffile action="delete" file="#VAL1b#">
		  <cfcatch type="any"><!--- Guess it was not a file, try a directory --->
			 <cfdirectory directory="#VALb1#" action="delete" recurse="yes">
		  </cfcatch>
	  </cftry>

   <!--- Rename --->
   <cfelseif Form.CMD is "move">
	  <cffile action="rename" source="#VAL1b#" destination="#VAL2#">

   <!--- Download --->
   <cfelseif Form.CMD is "download">

	 <!--- Strip the filename out of VAL 1 --->
	 <cfset ReverseFullPath = Reverse(VAL1b)>
	 <cfset SlashPosition = Find(sep,ReverseFullPath)>
	 <cfset CleanFilename = Left(ReverseFullPath, (SlashPosition - 1))>
	 <cfset CleanFilename = Reverse(CleanFilename)>

	 <!--- Strip out the full directory path --->
	 <cfset PathLen = Len(VAL1b)>
	 <cfset CleanDir = Left(VAL1b, ((PathLen - SlashPosition) + 1 ))>

	 <!--- Get the file size --->
	 <cfdirectory action="list" directory="#CleanDir#" filter="#CleanFilename#" name="DirList">

	 <!--- send the applet the file size --->
	 <cfheader name="Content-Length" value="#DirList.Size#">

	 <!--- send the file --->
	 <cfcontent file="#VAL1b#" type="application/octet-stream">
   </cfif>
   <cfabort>
</cfif>